<template>
  <div class="box">
    <div class="shop-info">
      <div class="shop-checkbox">
        <label>
          <input type="checkbox" :checked="check" @change="toggleChange({id})">
          <span></span>
        </label>
      </div>
      <div class="shop-img">
        <img :src="photo[0].url" alt="">
      </div>
      <div class="shop-text">
        <h2>{{title}}</h2>
        <p>销量<mark>{{saleNum}}</mark></p>
        <p class="p1">
          <span>价格￥ {{price}}</span>
          <van-stepper :value="count" @change="countChange"/>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  props: {
    id: {
      type: Number,
      required: true
    },
    price: {
      type: Number,
      required: true
    },
    title: {
      type: String,
      required: true
    },
    photo: {
      type: Array,
      required: true
    },
    count: {
      type: Number,
      required: true
    },
    check: {
      type: Boolean,
      required: true
    },
    saleNum: {
      type: Number,
      required: true
    }
  },
  methods: {
    ...mapMutations(['toggleChange']),
    countChange (num) {
      this.$store.commit('changeNum', { num, id: this.id })
    }
  }
}
</script>

<style lang="scss" scoped>
.box{
  width: 98%;
  height: 120px;
  margin: 0 auto;
  border-radius: 10px;
  // box-shadow: 0 0 10px #000000;
  background-color: white;
  box-sizing: border-box;
  padding: 5px;
  mark{
    color: red;
    background-color: whitesmoke;
  }
}
.shop-info{
  height: 100%;
  display: flex;
  /* border: 1px solid red; */
}
.shop-checkbox{
  width: 10%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  input{
    display: none;
    + span{
      display: block;
      width: 15px;
      height: 15px;
      position: relative;
      border: 1px solid #999;
      border-radius: 50%;
    }
    &:checked + span{
      background-color: rgba(68, 189, 50,1.0);
        &::after{
          content: '';
          position: absolute;
          width: 15px;
          height: 8px;
          border-left: 2px solid white;
          border-bottom: 2px solid white;
          transform: rotate(-45deg);
        }
    }
  }
}
.shop-img{
  width: 30%;
  height: 100%;
  /* box-sizing: border-box;
  padding: 5px; */
  text-align: center;
  /* border: 1px solid red; */
  img{
    width: 100%;
    height: 100%;
  }
}
.shop-text{
  width: 50%;
  margin-left: 5px;
  font-size: 12px;
  color: #576B95;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .p1{
    display: flex;
    justify-content: space-between;
  }
}
</style>
